<?php

class AdpushController extends Common {

    public function __construct() {
        parent::__construct();
        $this->load->model('advertisement');
        $this->load->model('advertisement_overflow');

    }

    /**
     * 圈发广告
     */
    public function listAction() {
        $page     = $this->get('page') ? $this->get('page') : 1;
        $pagesize = 10;
        $pagelist = $this->instance('pagelist');
        $pagelist->loadconfig();
        $where = '';
        $model = $this->model('advertisement');
        $total = $model->count('advertisement', 'id', $where);
        $urlparam = array(
            'page' => '{page}',
        );
        $data = $model->page_limit($page, $pagesize)->order(array('id DESC'))->select();
        $pagelist = $pagelist->total($total)->url(url('admin/adpush/list', $urlparam))->num($pagesize)->page($page)->output();
        $this->view->assign(array(
            'page' => $page,
            'data' => $data,
            'pagelist'=> $pagelist,
        )); //assign()对视图变量完成赋值
        $this->view->display('/admin/adpush/adpush_list');  //这里是对视图文件的加载
    }

    /**
     * 圈发广告详情
     */
    public function adPushInfoAction() {
        $ad_id = $this->get('ad_id');
        $page     = $this->get('page') ? $this->get('page') : 1;
        $pagesize = 10;
        $pagelist = $this->instance('pagelist');
        $pagelist->loadconfig();
        $where = ' ad_id = '.$ad_id ;
        $model = $this->model('advertisement_overflow');
        $total = $model->count('advertisement_overflow', 'id', $where);
        $urlparam = array(
            'page' => '{page}',
            'ad_id' => $ad_id,
        );
        $data = $model->where($where)->page_limit($page, $pagesize)->order(array('id DESC'))->select();
//        var_dump($data);exit;
        $pagelist = $pagelist->total($total)->url(url('admin/adpush/adPushInfo', $urlparam))->num($pagesize)->page($page)->output();
        $this->view->assign(array(
            'ad_id' => $ad_id,
            'page' => $page,
            'data' => $data,
            'pagelist'=> $pagelist,
        )); //assign()对视图变量完成赋值
        $this->view->display('/admin/adpush/adpushinfo_list');  //这里是对视图文件的加载
    }


}
